﻿var setting = {
    check: {
        chkboxType: { "Y": "ps", "N": "ps" },
        enable: true
    },
    data: {
        simpleData: {
            enable: true
        }
    }
};

//定义备选专家数组
var BXs = new Array();
var BXNDs = new Array();

//doExtract：获取专家分类树形
function getCategorys(str_url) {
    $.ajax({
        type: "GET",
        url: str_url,
        dataType: "json",
        success: function (data) {
            //初始化专业专家的所属分类
            $.fn.zTree.init($("#treeCategory"), setting, data);
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            alert(textStatus);
        },
        beforeSend: function () {
            // 发送前，禁止提交按钮，放置重复提交
            $("button,input,a").attr("disabled", "disabled");
        },
        complete: function () {
            // 完成后，回复提交按钮可用
            $("button,input,a").removeAttr("disabled");
        }
    });
}

//doExtract：显示备选专家列表
function showExpert() {
    if (BXs) {
        var listHtml = "";
        $.each(BXs, function (i) {
            listHtml += "<div style='pandding:5px 0px;'>";
            listHtml += "<span style='font-size:2em;'><strong>";
            listHtml += BXs[i].rowIDX + "：" + BXs[i].expName;
            listHtml += "</strong></span><br />";
            listHtml += "<span> " + BXs[i].expPhone + "；</span>";
            listHtml += "<span> " + BXs[i].expProfession + "；</span>";
            listHtml += "<span> " + BXs[i].expCompany + "；</span>";
            listHtml += "<span> " + BXs[i].expTitle + "；</span>";
            listHtml += "</div>";
        });

        $("#expList").html(listHtml);

        $("#expList").dialog({
            autoOpen: false,
            height: 530,
            width: 600,
            resizable: false,
            modal: true,
            draggable: true,
            title: "备选专家列表",
            buttons: {
                "关闭": function () { $(this).dialog("close"); }
            }
        });
        $("#expList").dialog("open");
    }
}

//doExtract：获取专家备选列表
function getExperts() {
    //根据专家分类勾选状态，获取专家的分类字符串，以逗号隔开
    var treeObj = $.fn.zTree.getZTreeObj("treeCategory");
    var nodes = treeObj.getCheckedNodes(true);
    var strIDs = "";
    if (nodes != null && nodes.length > 0) {
        for (var i = 0, l = nodes.length; i < l; i++) {
            var halfCheck = nodes[i].getCheckStatus();
            if (!halfCheck.half) {
                if (strIDs == "") {
                    strIDs = nodes[i].id;
                } else {
                    strIDs += "," + nodes[i].id;
                }
            }
        }
    }

    //获取抽取类型
    var valTypeName = $('input:radio[name="rdExtractType"]:checked').val();

    //拼凑查询条件
    var opParam = {
        opExtractId: $("#extractID").val(),
        opArea: $("#zjAreaCity").val(),
        opProfession: $("#txtProfessional").val(),
        opCategoryIDs: strIDs,
        opTypeName: valTypeName
    }

    $.ajax({
        url: strUrlgetExpertsBX,
        type: "POST",
        dataType: "json",
        data: JSON.stringify(opParam),
        contentType: 'application/json; charset=utf-8',
        success: function (data) {
            if (data != null && data != "unsigned") {
                if (data.ISOK) {
                    BXs.length = 0;
                    //BXs = null;
                    //备选
                    $.each(data.BXs, function (i) {
                        //拼凑滚动时显示的专家名
                        var str = data.BXs[i].expName;
                        str = "*" + str.substring(1);
                        if (str.length > 2) {
                            str = "*" + "*" + str.substring(2);
                        }
                        var bx = {
                            rowIDX: str,
                            eId: data.BXs[i].eId,
                            dId: data.BXs[i].dId,
                            dIsOK: data.BXs[i].dIsOK,
                            dDescribe: data.BXs[i].dDescribe,
                            expId: data.BXs[i].expId,
                            expName: data.BXs[i].expName,
                            expPhone: data.BXs[i].expPhone,
                            expProfession: data.BXs[i].expProfession,
                            expCompany: data.BXs[i].expCompany,
                            expTitle: data.BXs[i].expTitle
                        };
                        //保存记录
                        BXs.push(bx);
                    });

                    //备选nd
                    BXNDs.length = 0;
                    //BXNDs = null;
                    $.each(data.BXNDs, function (i) {
                        //拼凑滚动时显示的专家名
                        var str = data.BXNDs[i].expName;
                        str = "*" + str.substring(1);
                        if (str.length > 2) {
                            str = "*" + "*" + str.substring(2);
                        }
                        var bx = {
                            rowIDX: str,
                            eId: data.BXNDs[i].eId,
                            dId: data.BXNDs[i].dId,
                            dIsOK: data.BXNDs[i].dIsOK,
                            dDescribe: data.BXNDs[i].dDescribe,
                            expId: data.BXNDs[i].expId,
                            expName: data.BXNDs[i].expName,
                            expPhone: data.BXNDs[i].expPhone,
                            expProfession: data.BXNDs[i].expProfession,
                            expCompany: data.BXNDs[i].expCompany,
                            expTitle: data.BXNDs[i].expTitle
                        };
                        //保存记录
                        BXNDs.push(bx);
                    });

                    //显示查询结果的专家数量
                    $("#expertCount").html(BXs.length);


                    //初始化界面
                    initExtractForm();
                } else {
                    alertMSG("获取专家列表错误！错误代码如下：<br/>" + data.MESSAGE);
                }
            }
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            alertMSG("获取专家列表错误！错误代码如下：<br/>" + textStatus);
        },
        beforeSend: function () {
            // 发送前，禁止提交按钮，放置重复提交
            $("button,input,a").attr("disabled", "disabled");
        },
        complete: function () {
            // 完成后，回复提交按钮可用
            $("button,input,a").removeAttr("disabled");
        }
    });
}



//抽取的备选专家滚动状态
var i = 0,      //当前滚动的索引
		tmp,    //临时变量
		isScroll = false;   //是否处于滚动状态标识

//doExtract：开始备选专家姓名的滚动，时间间隔e，单位毫秒
function startxx(e) {
    if (typeof (BXs) == "undefined" ||
        typeof (BXs) == "null" ||
        BXs == null ||
        BXs == "" ||
        BXs.length == 0) {
        alertMSG("备选专家数量为0。不能进行随机抽取操作。");
        isScroll = false;
        return;
    }

    tmp = setInterval(function () {
        if (i < BXs.length) {
            $('#expertBXLB').html(BXs[i].rowIDX);
            i++;
        } else {
            i = 0;
            $('#expertBXLB').html(BXs[i].rowIDX);
            i++;
        }
    }, e);

    //设置状态
    $("#doExtractIcon").removeClass("ui-icon-play");
    $("#doExtractIcon").addClass("ui-icon-pause");
    $("#doExtractCaption").html("停止");
}

//doExtract：停止抽取滚动，获取当前的专家记录
function stopxx() {
    tmp = clearInterval(tmp);

    //获取一个专家信息
    extractOneExpert();
}

//doExtract：在备选专家列表中抽取一个专家
function extractOneExpert() {
    var selected_id = "";

    //在备选专家ID列表中选出一个
    if (BXNDs.length > 0) {
        //随机获取一个ID记录
        //selected_id = BXNDs[Math.floor(Math.random() * BXNDs.length)].expId;
        //获取内定专家的第一个
        selected_id = BXNDs[0].expId;
    } else {
        selected_id = BXs[Math.floor(Math.random() * BXs.length)].expId;
    }

    if (selected_id != "") {
        try {
            //循环专家备选列表，获取当前选中的专家记录，设置界面
            var selected_expert = null;
            for (var j = 0; j < BXs.length; j++) {
                if (selected_id == BXs[j].expId) {
                    selected_expert = BXs[j];
                    break;
                }
            }

            if (selected_expert != null) {
                //设置选中专家的姓名
                $("#expertBXLB").html(selected_expert.expName);

                //设置当前详细记录的数据
                selected_expert.dIsOK = false;
                var valTypeName = $('input:radio[name="rdExtractType"]:checked').val();
                selected_expert.dType = valTypeName;

                //为当前选定的专家添加抽取结果详细记录
                $.ajax({
                    url: strUrlnewAExtractDetail,
                    type: "POST",
                    dataType: "json",
                    data: JSON.stringify(selected_expert),
                    contentType: 'application/json; charset=utf-8',
                    success: function (data) {
                        if (data.ISOK) {
                            alertMSG("成功抽取到专家：" + selected_expert.expName);

                            //刷新当前备选专家记录
                            getExperts();

                            //刷新当前抽取记录的已选专家列表
                            getExtractDetails($("#extractID").val());

                        } else {
                            alertMSG("获取专家列表错误！错误代码如下：<br/>" + data.MESSAGE);

                            //初始化界面
                            initExtractForm();
                        }
                    },
                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                        alertMSG("抽取错误！错误代码如下：<br/>" + textStatus);
                    },
                    beforeSend: function () {
                        // 发送前，禁止提交按钮，放置重复提交
                        $("button,input,a").attr("disabled", "disabled");
                    },
                    complete: function () {
                        // 完成后，回复提交按钮可用
                        $("button,input,a").removeAttr("disabled");
                    }
                });
            } else {
                alertMSG("抽取失败，抽取到的专家信息错误。");
            }
        } catch (e) {
            alertMSG("抽取错误！请重新抽取。</ br>错误代码：" + e.Message);
            return;
        }
    } else {
        alertMSG("抽取错误！请重新抽取。");
        return;
    }
}

//doExtract：抽取一个专家
function extract() {
    isScroll = !isScroll;

    if (isScroll) {
        startxx(200);

    } else {
        stopxx();
    }
}

//数组删除指定位置的自定义方法
Array.prototype.del = function (n) {  //n表示第几项，从0开始算起。
    //prototype为对象原型，注意这里为对象增加自定义方法的方法。
    if (n < 0)  //如果n<0，则不进行任何操作。
        return this;
    else
        return this.slice(0, n).concat(this.slice(n + 1, this.length));
    /*
    concat方法：返回一个新数组，这个新数组是由两个或更多数组组合而成的。
      　　　　　　这里就是返回this.slice(0,n)/this.slice(n+1,this.length)
     　　　　　　组成的新数组，这中间，刚好少了第n项。
    slice方法： 返回一个数组的一段，两个参数，分别指定开始和结束的位置。

    //测试代码
    var test=new Array(0,1,2,3,4,5);
    test=test.del(3);  //从0算起，这里也就是删除第4项。
    alert(test);

    */
}


//保存当前抽取的专家记录到已选专家列表
function saveThisExtractDetail() {
    var thisSelectedExpertID = $('#SelectedExpertId').val();

    if (typeof (thisSelectedExpertID) != "undefined" && thisSelectedExpertID.length > 0) {
        //判断抽取结果描述是否输入，如果没有，提示要求输入
        if ($("#SelectedExpertDescribe").val() == null || $("#SelectedExpertDescribe").val() == "undefined" || $("#SelectedExpertDescribe").val() == "") {
            alertMSG("抽取结果描述没有输入！");
        } else {
            //添加当前选择的专家ID到已选专家ID列表
            expertYX_IDs.push(thisSelectedExpertID);

            //添加抽取记录
            var thisExtractDetail = new Object;
            thisExtractDetail.expertId = thisSelectedExpertID;
            thisExtractDetail.expertName = "";
            thisExtractDetail.expertPhone = "";
            thisExtractDetail.expertProfession = "";
            thisExtractDetail.expertUnit = "";
            thisExtractDetail.expertTitle = "";
            thisExtractDetail.extractIsOK = "N";
            thisExtractDetail.extractDescribe = "";
            thisExtractDetail.extractType = "";

            //设置抽取记录的类型，是专业专家还是商务专家
            var val = $('input:radio[name="extracOption"]:checked').val();
            if (val == null) {
                alert("请首先选择抽取专家类型!");
                return false;
            }
            else {
                if (val == "ZY") {
                    //专业专家
                    thisExtractDetail.extractType = "专业评委";
                } else {
                    //商务专家
                    thisExtractDetail.extractType = "商务评委";
                }
            }

            //设置抽取记录的是否参加评标
            if ($("#SelectedExpertIsOK").attr("checked") == true || $("#SelectedExpertIsOK").attr("checked") == "checked") {
                thisExtractDetail.extractIsOK = "Y";
            } else {
                thisExtractDetail.extractIsOK = "N";
            }

            if ($("#SelectedExpertDescribe").html() == null ||
            $("#SelectedExpertDescribe").html() == "undefined" ||
            $("#SelectedExpertDescribe").html().length == 0) {
                thisExtractDetail.extractDescribe = "";
            } else {
                thisExtractDetail.extractDescribe = $("#SelectedExpertDescribe").html();
            }


            //备选专家记录列表删除当前选择的记录
            for (i = 0; i < expertBXs_DO.length; i++) {
                if (expertBXs_DO[i].expertId == thisSelectedExpertID) {
                    //设置抽取记录的专家信息
                    thisExtractDetail.expertName = expertBXs_DO[i].expertName;
                    thisExtractDetail.expertPhone = expertBXs_DO[i].expertPhone;
                    thisExtractDetail.expertProfession = expertBXs_DO[i].expertProfession;
                    thisExtractDetail.expertUnit = expertBXs_DO[i].expertUnit;
                    thisExtractDetail.expertTitle = expertBXs_DO[i].expertTitle;

                    expertBXs_DO = expertBXs_DO.del(i);

                    break;
                }
            }

            //备选专家记录列表删除当前选择的记录
            for (i = 0; i < expertBXn_IDs_DO.length; i++) {
                if (expertBXn_IDs_DO[i] == thisSelectedExpertID) {
                    expertBXn_IDs_DO = expertBXn_IDs_DO.del(i);
                    break;
                }
            }

            //生成的抽取记录添加抽取记录列表
            extractDetails.push(thisExtractDetail);

            //初始化界面
            initExtractForm();

            //输出已选专家列表
            listextractDetails();
        }
    } else {
        alertMSG("保存当前选择的专家信息错误。请首先随机抽取一个专家。");
    }
}

//初始化抽取的界面
function initExtractForm() {
    //设置按钮状态
    $("#doExtract").removeAttr('disabled');
    $("#doExtractIcon").removeClass("ui-icon-pause");
    $("#doExtractIcon").addClass("ui-icon-play");
    $("#doExtractCaption").html("4.1、开始");

    //设置选中专家的信息
    $('#SelectedExpertId').val("");
    $("#expertBXLB").html("随机选取");
    $("#SelectedExpertName").html("");
    $("#SelectedExpertInfo").html("");

    $("#SelectedExpertIsOK").attr('checked', 'true');
    $("#SelectedExpertDescribe").val("");

    //启用滚动按钮
    $("#doExtract").removeAttr('disabled');
}

//输出已选专家列表到界面
function listextractDetails() {
    var strHTML = "";
    for (i = 0; i < extractDetails.length; i++) {
        //输出当前抽取记录专家的信息
        var strTMP = '<li style="padding: 5px; margin-bottom: 20px;">';


        //输出当前抽取记录专家的抽取信息
        if (extractDetails[i].extractIsOK == "Y") {
            strTMP += '<p><span style="margin-right: .3em; font-size: 1.3em; ">[' + extractDetails[i].extractType + ']' + extractDetails[i].expertName + '</span>' +
            '<span style="margin-right: .3em; padding-top: .3em;">' + '：' +
            extractDetails[i].expertPhone + '；' +
            extractDetails[i].expertUnit + '；' +
            extractDetails[i].expertTitle + '；' +
            extractDetails[i].expertProfession + '；</span></p>';

            strTMP +=
            '<p><span style="float:left; margin-right: .3em; padding-top: .3em; color: blue;">参加评标；</span>';
            strTMP += '<span><a href="';
            strTMP += 'javascript:delectThisExtractDetail(';
            strTMP += "'";
            strTMP += extractDetails[i].expertId;
            strTMP += "'";
            strTMP += ');"><span class="ui-icon ui-icon-trash" style="float: left;"></span>删除</a></span></p>';

            strTMP += '<p><span style="float:left; margin-right: .3em; padding-top: .3em; color: #444;">' + extractDetails[i].extractDescribe + '</span></p>';
        } else {
            strTMP += '<p><span style="margin-right: .3em; font-size: 1.3em; color: #444; ">[' + extractDetails[i].extractType + ']' + extractDetails[i].expertName + '</span>' +
            '<span style="margin-right: .3em; padding-top: .3em; color: #444;">' + '：' +
            extractDetails[i].expertPhone + '；' +
            extractDetails[i].expertUnit + '；' +
            extractDetails[i].expertTitle + '；' +
            extractDetails[i].expertProfession + '；</span></p>';

            strTMP +=
            '<p><span style="float:left; margin-right: .3em; padding-top: .3em; color: red;">不参加评标；</span>';
            strTMP += '<span><a href="';
            strTMP += 'javascript:delectThisExtractDetail(';
            strTMP += "'";
            strTMP += extractDetails[i].expertId;
            strTMP += "'";
            strTMP += ');"><span class="ui-icon ui-icon-trash" style="float: left;"></span>删除</a></span></p>';

            strTMP += '<p><span style="float:left; margin-right: .3em; padding-top: .3em; color: #444;">' + extractDetails[i].extractDescribe + '</span></p>';
        }

        strTMP += '</li>';
        strHTML += strTMP;
    }

    $("#extractDetails").html(strHTML);
}


function confirmsaveThisExtract() {
    $("#thisPageMsg").html("是否要保存当前抽取记录？");
    $("#thisPageMsg").dialog({
        modal: true,
        buttons: {
            "保存": function () {
                saveThisExtract();
            },
            "取消": function () {
                $(this).dialog("close");
            }
        }
    });
}

//保存当前抽取记录
function saveThisExtract() {
    //设置标题
    $("#extractRecord_Title").val($("#extractRecord_Title").val());

    //判断是否有关联项目列表
    if ($("#selectedProjectIDs").val() == null || $("#selectedProjectIDs").val() == "undefined" || $("#selectedProjectIDs").val() == "") {
        alertMSG("项目关联失败，提交数据错误。");
        return false;
    }

    var strTEMP;

    //拼凑抽取详细记录的是否参加列表
    strTEMP = "";
    for (i = 0; i < extractDetails.length; i++) {
        if (strTEMP == "") {
            strTEMP = extractDetails[i].extractIsOK;
        } else {
            strTEMP += "," + extractDetails[i].extractIsOK;
        }
    }
    $("#extractRecord_details_IsOK").val(strTEMP);

    //拼凑抽取详细记录的抽取结果描述列表
    strTEMP = "";
    for (i = 0; i < extractDetails.length; i++) {
        if (strTEMP == "") {
            strTEMP = extractDetails[i].extractDescribe;
        } else {
            strTEMP += "," + extractDetails[i].extractDescribe;
        }
    }
    $("#extractRecord_details_Describe").val(strTEMP);

    //拼凑抽取详细记录的抽取类型（专业、商务）列表
    strTEMP = "";
    for (i = 0; i < extractDetails.length; i++) {
        if (strTEMP == "") {
            strTEMP = extractDetails[i].extractType;
        } else {
            strTEMP += "," + extractDetails[i].extractType;
        }
    }
    $("#extractRecord_details_Type").val(strTEMP);

    //拼凑抽取详细记录的抽取结果专家ID列表
    strTEMP = "";
    for (i = 0; i < extractDetails.length; i++) {
        if (strTEMP == "") {
            strTEMP = extractDetails[i].expertId;
        } else {
            strTEMP += "," + extractDetails[i].expertId;
        }
    }
    $("#extractRecord_details_ExpertId").val(strTEMP);


    //提交表单
    $("#formOP").submit();
}

//删除指定专家ID的抽取结果记录
function delectThisExtractDetail(thisExpertId) {
    //删除抽取记录
    for (i = 0; i < extractDetails.length; i++) {
        if (extractDetails[i].expertId == thisExpertId) {
            //根据当前专家ID，查找备选专家列表，将找到的专家记录添加到滚动专家列表中
            for (idx = 0; idx < expertBXs.length; idx++) {
                if (expertBXs[idx].expertId == thisExpertId) {
                    //添加到专家滚动列表
                    var n = new Object;
                    n.expertId = expertBXs[idx].expertId;
                    n.expertName = expertBXs[idx].expertName;
                    n.expertPhone = expertBXs[idx].expertPhone;
                    n.expertProfession = expertBXs[idx].expertProfession;
                    n.expertUnit = expertBXs[idx].expertUnit;
                    n.expertTitle = expertBXs[idx].expertTitle;

                    expertBXs_DO.push(n);
                    break;
                }
            }

            /*
            //不需要恢复备选专家n滚动列表
            for (idx = 0; idx < expertBXn_IDs.length; idx++) {
            if (expertBXn_IDs[idx] == thisExpertId) {
            //添加到专家n滚动列表
            expertBXn_IDs_DO.push(thisExpertId);
            break;
            }
            }
            */

            //删除当前找到的抽取记录
            extractDetails = extractDetails.del(i);

            //刷新已抽取的列表
            initExtractForm();
            listextractDetails();

            break;
        }
    }

}

//判断并设置项目信息
function checkProject() {
    //1、获取关联项目ID
    var strP = $("#selectedProjectIDs").val();

    if (strP.length > 0) {
        //2、设置抽取关联项目数组
        extractProjects = strP.split(",");
        if (extractProjects.length > 0) {
            return true;
        } else {
            return false;
        }
    }
    else {
        return false;
    }
}

//获取抽取选项
function getExtractOption() {
    //按专家专业
    optionProfessions = $("#txtProfessional").val().split(",");

    //按专家分类
    var strC = "";
    var zTree = $.fn.zTree.getZTreeObj("treeCategory"),
            nodes = zTree.getCheckedNodes(true);
    for (var i = 0, l = nodes.length; i < l; i++) {
        if (!nodes[i].isParent) {
            if (strC == "") {
                strC = nodes[i].id;
            } else {
                strC += "," + nodes[i].id;
            }
        }
    }
    optionCategorys = strC.split(",");
    return true;
}

//Step1：获取勾选的项目IDs，提交网页至新建抽取记录页面
function step1NewExtractRecord() {
    try {
        //1、获取项目勾选信息
        var chbProjects = $("input[name='selectedProjectIDs']:checked");
        var strP = "";
        for (var i = 0, l = chbProjects.length; i < l; i++) {
            if (chbProjects[i].checked) {
                if (strP == "") {
                    strP = chbProjects[i].id;
                } else {
                    strP += "," + chbProjects[i].id;
                }
            }
        }

        if (strP.length <= 0) {
            alertMSG("关联项目没有选择。");
        }
        else {
            $("#selectedProjectIDs").val(strP);
            $("#formOP").submit();
        }
    } catch (e) {
        alertMSG("项目获取失败，提交数据错误。");
    }
}

//doExtract：获取指定抽取记录ID的抽取结果详细记录
function getExtractDetails(ExtractID) {
    $.ajax({
        url: strUrlgetExtractDetails,
        type: "POST",
        dataType: "json",
        // query will be the param used by your action method
        data: { extractID: ExtractID },
        success: function (data) {
            if (data.ISOK) {
                $("#tableDetails").html("");
                //填充关联项目表格
                $('#DataTemplate_Details').tmpl(data.details).appendTo('#tableDetails');
            } else {
                alertMSG("获取抽取详细记录错误，错误代码：" + data.MESSAGE);
            }
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            alert(textStatus);
        },
        beforeSend: function () {
            // 发送前，禁止提交按钮，放置重复提交
            $("button,input,a").attr("disabled", "disabled");
        },
        complete: function () {
            // 完成后，回复提交按钮可用
            $("button,input,a").removeAttr("disabled");
        }
    });
}

//doExtract：修改当前指定详细记录ID的详细记录
function editThisDetail(detailID) {
    //获取指定ID的详细记录
    var this_detail = new Object;
    $.ajax({
        url: strUrlgetExtractDetail,
        type: "POST",
        dataType: "json",
        // query will be the param used by your action method
        data: { dId: detailID },
        success: function (data) {
            if (data.ISOK) {
                //赋值，但是打开对话框
                $("#FormEditDetail_ExpertName").html(data.detail.expName);
                $("#FormEditDetail_ExpertMobile").html(data.detail.expPhone);
                $("#FormEditDetail_ExpertCompany").html(data.detail.expCompany);
                $("#FormEditDetail_ExpertTitle").html(data.detail.expTitle);
                if (data.detail.dIsOK) {
                    $("#FormEditDetail_isSelected").attr("checked", 'checked');
                } else {
                    $("#FormEditDetail_isSelected").attr("checked", false);
                }
                $("#FormEditDetail_describe").html(data.detail.dDescribe);
                $("#FormEditDetail_Id").val(data.detail.dId);

                $("#FormEdit").dialog("open");
            } else {
                alertMSG("获取抽取详细记录错误，错误代码：" + data.MESSAGE);
            }
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            alertMSG(textStatus);
        }
    });
}

//doExtract：保存当前指定详细记录ID的详细记录的修改
function saveThisDetail(detailID) {
    if (detailID != null && detailID != "") {
        var x = 1;
        if ($("#FormEditDetail_isSelected").is(":checked")) {
            x = 1;
        } else {
            x = 0;
        }
        var detail = {
            dId: $("#FormEditDetail_Id").val(),
            dIsOK: x,
            dDescribe: $("#FormEditDetail_describe").html()
        };

        $.ajax({
            url: strUrlsaveExtractDetail,
            type: "POST",
            dataType: "json",
            data: JSON.stringify(detail),
            contentType: 'application/json; charset=utf-8',
            success: function (data) {
                if (data.ISOK) {
                    //保存成功，清理界面
                    $("#FormEditDetail_ExpertName").val("");
                    $("#FormEditDetail_ExpertMobile").val("");
                    $("#FormEditDetail_ExpertCompany").val("");
                    $("#FormEditDetail_ExpertTitle").val("");
                    $("#FormEditDetail_isSelected").attr("checked", true);
                    $("#FormEditDetail_describe").html("");
                    $("#FormEditDetail_Id").html("");
                    //关闭对话框
                    $("#FormEdit").dialog("close");
                    //重新获取抽取结果的列表
                    getExtractDetails($("#extractID").val());
                } else {
                    alertMSG("保存抽取详细记录错误，错误代码：" + data.MESSAGE);
                }
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                alertMSG(textStatus);
            },
            beforeSend: function () {
                // 发送前，禁止提交按钮，放置重复提交
                $("button,input,a").attr("disabled", "disabled");
            },
            complete: function () {
                // 完成后，回复提交按钮可用
                $("button,input,a").removeAttr("disabled");
            }
        });
    }
    else {
        //关闭对话框
        $("#FormEdit").dialog("close");
    }
}

//导出当前的抽取记录到Excel表并下载
function exportThisExtract() {
    window.open("exportExtractRecordToExcel?id=" + $("#extractID").val());
}
